﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


using CrystalDecisions.CrystalReports.Engine;

namespace MainProgram
{
    public partial class FormDataHistory : Form
    {

#if DEBUG
        string reportPath = System.IO.Directory.GetCurrentDirectory().Replace("bin\\Debug", "ModelReport\\CrystalReport.rpt");
#else
        string reportPath = System.IO.Directory.GetCurrentDirectory().Replace("bin\\Release", "ModelReport\\CrystalReport.rpt");
#endif

        public FormDataHistory()
        {
            InitializeComponent();
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            MonitorDataClassesDataContext mdcdc=new MonitorDataClassesDataContext();

            var results = from item in mdcdc.NodeData
                          where (int)item.num == Convert.ToInt32(comboBoxEx1.Text)
                          where (DateTime)item.recvtime > dateTimePicker1.Value
                          where (DateTime)item.recvtime < dateTimePicker2.Value
                          select item;

            var resultsForReport = from item in results.ToList()
                                   where ((double?)item.GetType().GetProperty(comboBoxEx5.Text).GetValue(item, null)).HasValue
                                   where ((DateTime?)item.GetType().GetProperty("recvtime").GetValue(item, null)).HasValue
                                   where ((string)item.GetType().GetProperty("state").GetValue(item, null))!=null
                                   select new DataForReport((DateTime)item.recvtime, (double)item.GetType().GetProperty(comboBoxEx5.Text).GetValue(item, null), (string)item.state);

            ReportDocument myReport = new ReportDocument();
            myReport.Load(reportPath);
            myReport.SetDataSource(resultsForReport.ToList());
            crystalReportViewer1.ReportSource = myReport;
            crystalReportViewer1.RefreshReport();
        }
    }
}
